package com.aube.base.card;

import android.content.Context;
import android.widget.RelativeLayout;

import com.aube.base.card.InfoView;
import com.aube.base.card.QAViewEx;
import com.aube.base.card.QAViewUp;
import com.aube.base.card.QuizViewUp;
import com.aube.base.card.BaseCardNew;
import com.aube.base.card.QuizViewEx;
import com.aube.base.card.VSViewEx;
import com.aube.base.card.VSViewUp;
import com.aube.base.card.VoteViewEx;
import com.aube.base.card.VoteViewUp;
import com.aube.base.controller.DataManager;
import com.aube.base.model.TimeLinePiece;
import com.huyn.baseframework.model.ChannelDetail;
import com.huyn.baseframework.utils.Utils;

/**
 * Created by hill on 10/24.
 */
public class ViewGenerator {

    public static BaseCardNew getView(TimeLinePiece data, ChannelDetail channelDetail, Context context) {
        Utils.Log(Utils.LogType.DEBUG, "ViewGenerator", "getView: data.type = " + data.type);
        String type = data.type;
        BaseCardNew card = null;
        if (TimeLinePiece.TYPE_VOTE.equalsIgnoreCase(type)) {
            if(data.hasImgInOption()) {
                card = new VoteViewEx(context);
            } else {
                card = new VoteViewUp(context);
            }
        } else if (TimeLinePiece.TYPE_VS.equalsIgnoreCase(type)) {
            if(data.hasImgInOption()) {
                card = new VSViewEx(context);
            } else {
                card = new VSViewUp(context);
            }
        } else if (TimeLinePiece.TYPE_QA.equalsIgnoreCase(type)) {
            if(data.hasImgInOption()) {
                card = new QAViewEx(context);
            } else {
                card = new QAViewUp(context);
            }
        } else if (TimeLinePiece.TYPE_INFO.equalsIgnoreCase(type)) {
            card = new InfoView(context);
        } else if (TimeLinePiece.TYPE_QUIZ.equalsIgnoreCase(type)) {
            //判断是否应该展示卡片,如果之前没有选过,就返回空
            int selectedIndex = DataManager.getInstance(context).getIndex(data.getRid());
            Utils.Log("QuizView", "getView: QUIZ. selectedIndex = " + DataManager.getInstance(context).getIndex(data.getRid()));
            if(selectedIndex < 0 && data.showQuizResult)
                return null;
            if(data.optionSize() == 2) {
                card = new QuizViewUp(context);
                Utils.Log("QuizView", "getView: QUIZ: option size = 2");
            } else if(data.optionSize() > 2) {
                card = new QuizViewEx(context);
                Utils.Log("QuizView", "getView: QUIZ: option size = " + data.optionSize());
            }

        }

        if(card != null)
            card.init(data, channelDetail);
        return card;
    }

    public static void generateParamsStyle(RelativeLayout.LayoutParams params, int relativeMode) {
        switch (relativeMode) {
            case 0:
                params.addRule(RelativeLayout.CENTER_IN_PARENT);
                break;
            case 1:
                params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
                break;
            case 2:
                params.addRule(RelativeLayout.CENTER_HORIZONTAL);
                break;
            case 3:
                params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                break;
            case 4:
                params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                params.addRule(RelativeLayout.CENTER_VERTICAL);
                break;
            case 5:
                params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                break;
            case 6:
                params.addRule(RelativeLayout.CENTER_HORIZONTAL);
                params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                break;
            case 7:
                params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                break;
            case 8:
                params.addRule(RelativeLayout.CENTER_VERTICAL);
                break;
        }
    }

}
